package com.sto.stoapp.activity.scanner.inquiry;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

import com.sto.stoapp.StoApplication;
import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.InquiryCastAdapter;
import com.sto.stoapp.adapter.InquiryFlightComAdapter;
import com.sto.stoapp.adapter.InquirySelectAdapter;
import com.sto.stoapp.adapter.InquiryStatisticsAdapter;
import com.sto.stoapp.dataprocess.ProcessUploadData;
import com.sto.stoapp.db.StoTableName;
import com.sto.stoapp.db.manager.CastManager;
import com.sto.stoapp.entity.FlightCompareEntity;
import com.sto.stoapp.entity.StatisticsEntity;
import com.sto.stoapp.listener.StoOnClickListener;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.status.EnumTableNames;
import com.sto.stoapp.thread.BaseThread;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.util.UnifiedStaticType;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import sto.android.app.StoPdaKeyEvent;


@SuppressLint("NewApi")
public class InquirySelectActivity extends TabActivity implements
		OnTabChangeListener {

	private ListView todayList;
	private ListView yesterdayList;
	private ListView beforeYesterdayList;
	private ListView everyoneDayList;
	private Button backToday, backYesterday, backBeforeYesterday, backEveryDay,left_everyday_button,left_before_yesterday_button,left_today_button,left_yesterday_button;
	private Button textToday, textYesterday, textBeforeYesterday, textEveryDay;

	private final int INT_TODAY = 0;// 今天
	private final int INT_YESTERDAY = 1;// 昨天
	private final int INT_BEFORE_YESTERDAY = 2;// 前天
	private final int INT_EVERYONE_DAY = 3;// 任意一天
	private final int FIRST_ITEM = R.string.all_statistics;// 表示选择了业务统计
	private final int CAST_INQUIRE = R.string.cast_inquire; // 到包预报查询
	private final int FLIGHT_COMPARE = R.string.flight_compare; // 航班对比查询
	private final int RESULT = 0x11;
	private final int COUNT = 0x12;
	private int dateItem = -1;
	private int nameItem = -1;// 获取上级点击项
	private int tableItem = -2;

	// ISCLICK=false表示点击了事件，true没点击
	private Boolean ISCLICK = true;

	private final String TODAY = "today";
	private final String YESTERDAY = "yesterday";
	private final String BEFORE_YESTERDAY = "before_yesterday";
	private final String EVERYONE_DAY = "everyoneDay";
	
	private String listItemText;// 获取上级点击记录查询名称

	private InquirySelectAdapter courierAdapter;
	private InquiryStatisticsAdapter statisticsAdapter;
	private InquiryCastAdapter castAdapter; // 到包预报adapter
	private InquiryFlightComAdapter flightCompareAdapter; // 航班对比adapter
	private List<StatisticsEntity> statisticsList;
	private TabHost myTabhost;
	private InquiryFieldSql fieldSql;
	private StoTableName stoTableName;
	private List<HashMap<String, String>> courierDatas = new ArrayList<HashMap<String, String>>();

	private List<FlightCompareEntity> castLists; // 显示到包预报航班
	protected List<FlightCompareEntity> flightCompareLists; // 航班对比

	@SuppressLint("ResourceAsColor")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

		myTabhost = this.getTabHost();
		LayoutInflater.from(this).inflate(R.layout.sto_inquiry_layoutlist,
				myTabhost.getTabContentView(), true);

		// 设置标题框
		// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
		// R.layout.dap_activity_head);// R.layout.custom_title_1就是传说中自定义布局
		// title = (TextView) findViewById(R.id.title);
		// title.setText(R.string.out_station);

		nameItem = this.getIntent().getIntExtra("inquiryNameItem", -1);
		tableItem = this.getIntent().getIntExtra("inquiryTableItem", -1);
		listItemText = this.getIntent().getStringExtra("inquiryItemText");

		fieldSql = new InquiryFieldSql();
		stoTableName = new StoTableName();

		initWidget();
		// 设置tabweight背景色
		myTabhost.setBackgroundColor(R.color.black);
		// myTabhost.setBackgroundResource(R.drawable.tabhost_bg);

		addTabHost();
		myTabhost.setOnTabChangedListener(this);
		setTabWeightFocus();
		// 监听任意一天的tab
		myTabhost.getTabWidget().getChildAt(INT_EVERYONE_DAY)
				.setOnClickListener(everyClickListener);
		onTabChanged(TODAY);
		myTabhost.setCurrentTab(0);// 设置默认选中项
	}

	/**
	 * 初始化控件ID
	 */
	private void initWidget() {
		backToday = (Button) findViewById(R.id.back_today);
		backYesterday = (Button) findViewById(R.id.back_yesterday);
		backBeforeYesterday = (Button) findViewById(R.id.back_before_yesterday);
		backEveryDay = (Button) findViewById(R.id.back_everyday);
		
		textToday = (Button) findViewById(R.id.text_today);
		textYesterday = (Button) findViewById(R.id.text_yesterday);
		textBeforeYesterday = (Button) findViewById(R.id.text_before_yesterday);
		textEveryDay = (Button) findViewById(R.id.text_everyday);
		
		todayList = (ListView) findViewById(R.id.inquiry_todayList);
		yesterdayList = (ListView) findViewById(R.id.inquiry_yesterdayList);
		beforeYesterdayList = (ListView) findViewById(R.id.inquiry_beforeYesterdayList);
		everyoneDayList = (ListView) findViewById(R.id.inquiry_everyoneDayList);

		/*
		 * @修改内容：预报查询和航班对比查询特殊处理
		 * 
		 * @修改人：mgf
		 */
		if (nameItem != FIRST_ITEM && nameItem != FLIGHT_COMPARE
				&& nameItem != CAST_INQUIRE) {
			todayList.setOnItemClickListener(itemClickListener);
			yesterdayList.setOnItemClickListener(itemClickListener);
			beforeYesterdayList.setOnItemClickListener(itemClickListener);
			everyoneDayList.setOnItemClickListener(itemClickListener);

		}
		// 点击到包预报
		if (nameItem == CAST_INQUIRE) {
			todayList.setOnItemClickListener(castClickListener);
			yesterdayList.setOnItemClickListener(castClickListener);
			beforeYesterdayList.setOnItemClickListener(castClickListener);
			everyoneDayList.setOnItemClickListener(castClickListener);
	
		}

		backToday.setOnClickListener(ClickListener);
		backYesterday.setOnClickListener(ClickListener);
		backBeforeYesterday.setOnClickListener(ClickListener);
		backEveryDay.setOnClickListener(ClickListener);

		left_everyday_button=(Button) findViewById(R.id.left_everyday_button);
		left_everyday_button.setFocusable(false);
		findViewById(R.id.text_everyday).setFocusable(false);
		left_today_button=(Button) findViewById(R.id.left_today_button);
		left_today_button.setFocusable(false);
		findViewById(R.id.text_today).setFocusable(false);
		left_yesterday_button=(Button) findViewById(R.id.left_yesterday_button);
		left_yesterday_button.setFocusable(false);
		findViewById(R.id.text_yesterday).setFocusable(false);
		left_before_yesterday_button=(Button) findViewById(R.id.left_before_yesterday_button);
		left_before_yesterday_button.setFocusable(false);
		findViewById(R.id.text_before_yesterday).setFocusable(false);
	}

	/**
	 * 首次进入界面选中第一个tabWeight
	 */
	private void setTabWeightFocus() {
		myTabhost.getTabWidget().getChildAt(INT_TODAY).setFocusable(true);
		myTabhost.getTabWidget().getChildAt(INT_TODAY)
				.setFocusableInTouchMode(true);
		myTabhost.getTabWidget().getChildAt(INT_YESTERDAY)
				.setFocusableInTouchMode(true);
		myTabhost.getTabWidget().getChildAt(INT_BEFORE_YESTERDAY)
				.setFocusableInTouchMode(true);
		myTabhost.getTabWidget().getChildAt(INT_EVERYONE_DAY)
				.setFocusableInTouchMode(true);
		myTabhost.getTabWidget().getChildAt(INT_TODAY).requestFocus();
	}

	/**
	 * 初始化tabHost数据格式
	 */
	private void addTabHost() {

		myTabhost.addTab(myTabhost.newTabSpec(TODAY)
				.setIndicator(getString(R.string.today), null)
				.setContent(R.id.tabInquiry_today));

		myTabhost.addTab(myTabhost.newTabSpec(YESTERDAY)
				.setIndicator(getString(R.string.yesterday), null)
				.setContent(R.id.tabInquiry_yesterday));

		myTabhost.addTab(myTabhost.newTabSpec(BEFORE_YESTERDAY)
				.setIndicator(getString(R.string.before_yesterday), null)
				.setContent(R.id.tabInquiry_before_yesterday));

		myTabhost.addTab(myTabhost.newTabSpec(EVERYONE_DAY)
				.setIndicator(getString(R.string.everyoneday_month), null)
				.setContent(R.id.tabInquiry_everyoneDay));
		TabWidget tabWidget = this.getTabWidget();
		for (int i = 0; i < tabWidget.getChildCount(); i++) {
			TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(
					android.R.id.title);
			tv.setTextColor(Color.WHITE);
		}
	}

	/**
	 * 获取当天/昨天/前天/任意一天的数据
	 * 
	 * @param itemText
	 * @param index
	 */
	@SuppressLint("SimpleDateFormat")
	public boolean onCreateOptionsMenu(int myMenuSettingTag) {
		String tablename = EnumTableNames.values()[tableItem].getTableName();
		fieldSql.setInquirytablename(tablename);
		fieldSql.setIndex_id(tableItem);
		fieldSql.setTitle_id(nameItem);

		switch (myMenuSettingTag) {
		case INT_TODAY:
			textToday.setText(listItemText);
			SimpleDateFormat sDateFormat = new SimpleDateFormat(
					UnifiedStaticType.DATE_FORMAT);
			String date = sDateFormat.format(new java.util.Date());

			fieldSql.setInquiryField(new String[] { date });

			startInquiryActivity();
			break;
		case INT_YESTERDAY:
			textYesterday.setText(listItemText);
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.DATE, -1);
			String yesterdayDate = new SimpleDateFormat(
					UnifiedStaticType.DATE_FORMAT).format(cal.getTime());

			fieldSql.setInquiryField(new String[] { yesterdayDate });

			startInquiryActivity();
			break;
		case INT_BEFORE_YESTERDAY:

			textBeforeYesterday.setText(listItemText);
			Calendar cal1 = Calendar.getInstance();
			cal1.add(Calendar.DATE, -2);
			String beforeYesterdayDate = new SimpleDateFormat(
					UnifiedStaticType.DATE_FORMAT).format(cal1.getTime());

			fieldSql.setInquiryField(new String[] { beforeYesterdayDate });
			startInquiryActivity();
			break;
		case INT_EVERYONE_DAY:
			textEveryDay.setText(listItemText);

			if (StoApplication.DeviceModel_420.equals(Helper.getPDAType()))
				show420Dialog();
			else
				showOtherDialog();

			break;

		default:
			break;
		}
		return false;
	}

	private void showOtherDialog() {

		Calendar c = Calendar.getInstance();
		final DatePickerDialog diag;
		diag = new DatePickerDialog(this, null, c.get(Calendar.YEAR),
				c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
		diag.setTitle("请选择日期");
		diag.setButton(DialogInterface.BUTTON1, "查询月",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						int year = diag.getDatePicker().getYear();
						int month = diag.getDatePicker().getMonth() + 1;
						String strMonth = null;
						if (0 < month && month < 10) {
							strMonth = "0" + month;
						} else {
							strMonth = "" + month;
						}
						String date = new StringBuilder().append("%")
								.append(strMonth).append("-").append("%")
								.append(year).toString();
						fieldSql.setInquiryField(new String[] { date });
						diag.dismiss();
						startInquiryActivity();
					}
				});

		diag.setButton(DialogInterface.BUTTON3, "查询日",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						int year = diag.getDatePicker().getYear();
						int month = diag.getDatePicker().getMonth() + 1;
						int dayOfMonth = diag.getDatePicker().getDayOfMonth();
						String strMonth = null;
						String strDayOfMonth = null;
						if (0 < month && month < 10) {
							strMonth = "0" + month;
						} else {
							strMonth = "" + month;
						}
						if (0 < dayOfMonth && dayOfMonth < 10) {
							strDayOfMonth = "0" + dayOfMonth;
						} else {
							strDayOfMonth = "" + dayOfMonth;
						}
						String time = new StringBuilder().append(strMonth)
								.append("-").append(strDayOfMonth).append("-")
								.append(year).toString();
						fieldSql.setInquiryField(new String[] { time });
						diag.dismiss();
						startInquiryActivity();
					}
				});

		diag.setButton(DialogInterface.BUTTON2, "取消",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						diag.dismiss();
					}
				});

		diag.show();

	}

	// 获取日期的Dialog
	private void show420Dialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(
				InquirySelectActivity.this);
		builder.setTitle("请选择日期");
		final DatePicker datePicker = new DatePicker(InquirySelectActivity.this);
		builder.setView(datePicker);
		final AlertDialog diag = builder.create();
		diag.setButton(DialogInterface.BUTTON1, "查询月",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

						int year = datePicker.getYear();
						int month = datePicker.getMonth() + 1;
						String strMonth = null;
						if (0 < month && month < 10) {
							strMonth = "0" + month;
						} else {
							strMonth = "" + month;
						}
						String date = new StringBuilder().append("%")
								.append(strMonth).append("-").append("%")
								.append(year).toString();
						fieldSql.setInquiryField(new String[] { date });
						diag.dismiss();
						startInquiryActivity();

					}
				});

		diag.setButton(DialogInterface.BUTTON3, "查询日",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						int year = datePicker.getYear();
						int month = datePicker.getMonth() + 1;
						int dayOfMonth = datePicker.getDayOfMonth();
						String strMonth = null;
						String strDayOfMonth = null;
						if (0 < month && month < 10) {
							strMonth = "0" + month;
						} else {
							strMonth = "" + month;
						}
						if (0 < dayOfMonth && dayOfMonth < 10) {
							strDayOfMonth = "0" + dayOfMonth;
						} else {
							strDayOfMonth = "" + dayOfMonth;
						}
						String time = new StringBuilder().append(strMonth)
								.append("-").append(strDayOfMonth).append("-")
								.append(year).toString();
						fieldSql.setInquiryField(new String[] { time });
						diag.dismiss();
						startInquiryActivity();
					}
				});

		diag.setButton(DialogInterface.BUTTON2, "取消",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						diag.dismiss();
					}
				});
		diag.show();
	}

	/**
	 * 切换Tab自动调用的事件
	 */
	@Override
	public void onTabChanged(String tabId) {

		if (!ISCLICK)
			return;
		dateItem = -1;
		if (tabId.equals(TODAY)) {
			dateItem = INT_TODAY;
		} else if (tabId.equals(YESTERDAY)) {
			dateItem = INT_YESTERDAY;
		} else if (tabId.equals(BEFORE_YESTERDAY)) {
			dateItem = INT_BEFORE_YESTERDAY;
		} else if (tabId.equals(EVERYONE_DAY)) {
			dateItem = INT_EVERYONE_DAY;
		}

		onCreateOptionsMenu(dateItem);
	}

	/**
	 * 监听点击记录信息
	 */
	StoOnClickListener ClickListener = new StoOnClickListener(this) {

		@Override
		public void mHonClick(View view) {
			finish();
		}
	};

	/**
	 * 监听点击记录信息
	 */
	StoOnItemClickListener itemClickListener = new StoOnItemClickListener(this) {

		@Override
		public void KcOnItemClickListener(AdapterView<?> parent, View view,
				int position, long id) {
			String code = courierDatas.get(position).get(fieldSql.INQUIRYCODE);
			InquiryDetail(code, position);
		}
	};

	/**
	 * 点击到包预报跳转到记录显示页面
	 */
	StoOnItemClickListener castClickListener = new StoOnItemClickListener(this) {

		@Override
		public void KcOnItemClickListener(AdapterView<?> parent, View view,
				int position, long id) {
			Intent intent = new Intent(InquirySelectActivity.this,
					ShowCastRecordActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.putExtra("date", castLists.get(position).getDate());
			intent.putExtra("flight", castLists.get(position).getFlight());
			startActivity(intent);
		}
	};

	/**
	 * 监听任意一天tabWeight
	 */
	StoOnClickListener everyClickListener = new StoOnClickListener(this) {

		@Override
		public void mHonClick(View view) {
			ISCLICK = false;
			myTabhost.setCurrentTab(INT_EVERYONE_DAY);// 设置选中项3
			dateItem = INT_EVERYONE_DAY;
			onCreateOptionsMenu(dateItem);
			ISCLICK = true;
		}
	};

	private void InquiryDetail(String code, int position) {
		InquiryDetail detail = new InquiryDetail(this, fieldSql, stoTableName);
		detail.inquiryFunctionDetail(code, fieldSql.getIndex_id(),
				courierAdapter, courierDatas, position);
	}

	private void startInquiryActivity() {
		if (courierDatas.size() > 0) {
			courierDatas.clear();
			courierAdapter.notifyDataSetChanged();
		}
		if (bufferThread != null) {
			bufferThread.cancelDialog();
			bufferThread = null;
		}
		startBufferThread();
	}

	BufferThread bufferThread;

	private void startBufferThread() {
		bufferThread = new BufferThread(this);
		bufferThread.start();
	}

	Handler handler = new Handler() {

		public void handleMessage(Message msg) {
			super.handleMessage(msg);

			if (msg.what == RESULT) {
				left_today_button.setText("0");
				left_before_yesterday_button.setText("0");
				left_yesterday_button.setText("0");
				left_everyday_button.setText("0");
				showToast(msg.obj.toString());
				// InquirySelectActivity.this.finish();
			}
			if (msg.what == COUNT) {
				left_today_button.setText("" + msg.obj);
				left_before_yesterday_button.setText("" + msg.obj);
				left_yesterday_button.setText("" + msg.obj);
				left_everyday_button.setText("" + msg.obj);
			}
		}
	};

	/**
	 * 查询数据缓冲线程
	 * 
	 * @author Administrator
	 * 
	 */
	class BufferThread extends BaseThread {

		private Context context;

		public BufferThread(Context context) {
			super(context);
			this.context = context;
			showDialog();
		}

		@Override
		public void run() {
			super.run();
			int count = 0;

			if (nameItem == FIRST_ITEM) {// 业务统计
				InquiryStatistics statistics = new InquiryStatistics(
						InquirySelectActivity.this, stoTableName);
				statisticsList = statistics.statisticsDataStatus(fieldSql);
				count = statisticsList == null ? 0 : statisticsList.size();
			} else if (nameItem == CAST_INQUIRE) { // 到包预报查询
				castLists = CastManager.getInstance(InquirySelectActivity.this)
						.queryFlightAndCountByDate(
								fieldSql.getInquiryField()[0]);
				count = (castLists == null ? 0 : castLists.size());
			} else if (nameItem == FLIGHT_COMPARE) { // 航班对比
				InquiryFlightCompare flightCompare = new InquiryFlightCompare(
						InquirySelectActivity.this);
				flightCompareLists = flightCompare
						.getFlightCompareRecords(fieldSql);
				count = (flightCompareLists == null ? 0 : flightCompareLists
						.size());
			} else {
				InquiryQueryTable querytable = new InquiryQueryTable(context);
				courierDatas = querytable.queryAll(fieldSql);
				count = courierDatas == null ? 0 : courierDatas.size();
			}
			cancelDialog();
			if (count > 0) {
				Message msg = handler.obtainMessage();
				msg.what = COUNT;
				msg.obj = count;
				handler.sendMessage(msg);
			} else {
				Message msg = handler.obtainMessage();
				msg.what = RESULT;
				msg.obj = "无记录信息";
				handler.sendMessage(msg);
				return;

			}
			runOnUiThread(new Runnable() {

				@Override
				public void run() {
					if (nameItem == FIRST_ITEM) {// 业务统计
						statisticsAdapter = new InquiryStatisticsAdapter(
								context, statisticsList);
						switch (dateItem) {
						case INT_TODAY:
							todayList.setAdapter(statisticsAdapter);
							break;
						case INT_YESTERDAY:
							yesterdayList.setAdapter(statisticsAdapter);
							break;
						case INT_BEFORE_YESTERDAY:
							beforeYesterdayList.setAdapter(statisticsAdapter);
							break;
						case INT_EVERYONE_DAY:
							everyoneDayList.setAdapter(statisticsAdapter);
							break;
						default:
							break;
						}
					}
					// 预报查询
					else if (nameItem == CAST_INQUIRE) {
						castAdapter = new InquiryCastAdapter(
								InquirySelectActivity.this, castLists);
						switch (dateItem) {
						case INT_TODAY:
							todayList.setAdapter(castAdapter);
							break;
						case INT_YESTERDAY:
							yesterdayList.setAdapter(castAdapter);
							break;
						case INT_BEFORE_YESTERDAY:
							beforeYesterdayList.setAdapter(castAdapter);
							break;
						case INT_EVERYONE_DAY:
							everyoneDayList.setAdapter(castAdapter);
							break;
						default:
							break;
						}
					}
					// 航班对比
					else if (nameItem == FLIGHT_COMPARE) {
						flightCompareAdapter = new InquiryFlightComAdapter(
								InquirySelectActivity.this, flightCompareLists);
						switch (dateItem) {
						case INT_TODAY:
							todayList.setAdapter(flightCompareAdapter);
							break;
						case INT_YESTERDAY:
							yesterdayList.setAdapter(flightCompareAdapter);
							break;
						case INT_BEFORE_YESTERDAY:
							beforeYesterdayList
									.setAdapter(flightCompareAdapter);
							break;
						case INT_EVERYONE_DAY:
							everyoneDayList.setAdapter(flightCompareAdapter);
							break;
						default:
							break;
						}
					} else {
						courierAdapter = new InquirySelectAdapter(context,
								courierDatas, fieldSql);
						switch (dateItem) {
						case INT_TODAY:
							todayList.setAdapter(courierAdapter);
							break;
						case INT_YESTERDAY:
							yesterdayList.setAdapter(courierAdapter);
							break;
						case INT_BEFORE_YESTERDAY:
							beforeYesterdayList.setAdapter(courierAdapter);
							break;
						case INT_EVERYONE_DAY:
							everyoneDayList.setAdapter(courierAdapter);
							break;
						default:
							break;
						}
					}
				}
			});
		}
	}

	private void showToast(String content) {
		Toast.makeText(this, content, Toast.LENGTH_LONG).show();
	}

	// 监听按键
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		keyCode=StoApplication.getStoJni().getEventFuction(keyCode);
		switch (keyCode) {
		case StoPdaKeyEvent.KEYCODE_1:
			Intent intent = new Intent(UnifiedStaticType.UP_ACTION);
			intent.putIntegerArrayListExtra(UnifiedStaticType.UPLOAD_TYPE,
					new ProcessUploadData().sendAllData());
			sendBroadcast(intent);
			break;
		default:
			break;
		}
		return super.onKeyUp(keyCode, event);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		courierDatas.clear();
		if (statisticsList != null) {
			statisticsList.clear();
			statisticsList = null;
		}
		if (castLists != null) {
			castLists.clear();
			castLists = null;
		}
		if (flightCompareLists != null) {
			flightCompareLists.clear();
			flightCompareLists = null;
		}
		if (myTabhost != null) {
			myTabhost.clearAllTabs();
			myTabhost = null;
		}
		if (bufferThread != null) {
			bufferThread.cancelDialog();
		}
		handler.removeMessages(RESULT);
		super.onDestroy();
	}

}
